<template>
	<div class="news-box scroll">
		<div>
			<headerNav></headerNav>
			<serviceIcon></serviceIcon>
			<div class="newsbanner">
				<div class="newstitle cbody">
					<h4>新闻动态
					<p>NEWS AND TRENDS</p>
				</h4>
				</div>
			</div>
			<div class="newslist">
				<div class="cbody">
					<h4>
					<span>新闻动态</span>
					<p class="pp"></p>
				</h4>
					<div class="scroll">
						<div class="newslists clearfix">
							<div class="newsitem" @click="gotoDetails(items)" v-for="(items,index) in newsList" :key="index">
								<div class="imgs"><img :src="items.imageUrl" /></div>

								<p class="title">{{items.title}}</p>
								<p class="date">DATE：{{util.formatDateTime(items.releaseTime)}}</p>
								<div class="newsitem_details">
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<footerNav></footerNav>
		</div>
	</div>
</template>

<script>
	import headerNav from './template/header'
	import serviceIcon from './template/service'
	import footerNav from './template/footer'
	import api from '../../api/loginApi'
	import util from '../../common/js/util'
	import scrollBox from './template/scrollBox'
	export default {
		data() {
			return {
				newsList: [],
				pageList: [],
				util: util,
				pageNo: 1,
				pageSize: 18,
				isLoad: false,
				fullHeight: document.documentElement.clientHeight
			}
		},
		components: {
			headerNav,
			serviceIcon,
			footerNav,
			scrollBox
		},
		methods: {
			gotoDetails(items) {
				this.$router.push({
					path: '/newsDetails?articleId=' + items.articleId
				});
			},
			getNewlyDynamicList: function() {
				if(this.isLoad) {
					return
				}
				this.isLoad = true
				var par = {
					pageNo: this.pageNo,
					pageSize: this.pageSize
				}
				api.getNewlyDynamicList(par, (res) => {
					//					res = JSON.parse(res);
					if(res.code == 0) {
						if(res.data.length > 0) {
							this.pageNo = this.pageNo + 1;
							this.newsList = this.newsList.concat(res.data);
							this.pageList = res.pageInfo;
						}
					}
					this.isLoad = false
				});
				
			},
			//下拉加载
			handleScroll() {
				//获取页面高度
				var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
				//滚动条离底部的距离
				var lodingM = document.body.offsetHeight - scrollTop
				if(lodingM < 1400) {
					var self = this;
					//当总页数小于当前页数 停在加载
					if(self.pageList.totalPages >= self.pageNo) {
						this.getNewlyDynamicList();
					}				
				} 
			},
		},
		beforeRouteLeave(to, from, next) {
			this.$destroy();
			next();
		},
		mounted() {
			this.getNewlyDynamicList();
			window.addEventListener('scroll', this.handleScroll)
		}
	}
</script>

<style lang="scss">
	.news-box {
		background: #FFFFFF;
		height: 100%;
		overflow: auto;
		h4,
		p {
			margin: 0;
		}
		.cbody {
			width: 1280px;
			margin: 0 auto;
		}
		.newsbanner {
			position: relative;
			background: #fff;
			margin-bottom: 90px;
		}
		.newstitle {
			height: 350px;
			background: url('../../../static/images/news.jpg') no-repeat;
			background-size: 100% auto;
			/*background-attachment: fixed;*/
		}
		.newstitle h4 {
			font-size: 36px;
			font-family: MicrosoftYaHei;
			color: #fff;
			text-align: center;
			font-weight: normal;
			position: absolute;
			margin: 0;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			-ms-transform: translate(-50%, -50%);
			/* IE 9 */
			-webkit-transform: translate(-50%, -50%);
			/* Safari and Chrome */
			-o-transform: translate(-50%, -50%);
			/* Opera */
			-moz-transform: translate(-50%, -50%);
			/* Firefox */
		}
		.newstitle h4 p {
			margin: 20px 0 0 0;
		}
		.newslist {
			padding-top: 50px;
			padding-bottom: 100px;
		}
		.newslist h4 {
			font-family: MicrosoftYaHei;
			text-align: center;
			font-weight: normal;
		}
		.newslist h4 span {
			font-size: 24px;
			color: #222222;
			font-weight: bold;
		}
		.newslist h4 p {
			font-size: 24px;
			color: #222222;
			margin-top: 20px;
		}
		.newslist h4 span:after {
			content: "";
			display: block;
			margin: 10px auto 0;
			width: 35px;
			height: 4px;
			background: #2B89FC;
		}
		.newslists {
			margin-top: 80px;
			padding: 0 50px;
		}
		.newListover {
			max-height: 2188px;
			overflow: auto;
			padding: 0 41px !important;
		}
		.newsitem {
			width: 380px;
			margin-right: 20px;
			margin-bottom: 89px;
			float: left;
			position: relative;
			overflow: hidden;
			border-radius: 4px;
			background: #fff;
			&:hover {
				cursor: pointer;
			}
		}
		.newsitem:nth-child(3n) {
			margin-right: 0;
		}
		.newsitem img {
			height: 294px;
			width: 380px;
			overflow: hidden;
			transition: all 0.35s linear;
			-webkit-transition: all 0.35s linear;
		}
		.newsitem .imgs {
			position: relative;
			display: block;
			width: 100%;
			height: 294px;
			background: #000;
		}
		.newsitem .imgs::before,
		.newsitem .imgs::after {
			position: absolute;
			z-index: 1;
			top: 45px;
			right: 60px;
			bottom: 45px;
			left: 60px;
			content: '';
			opacity: 0;
			-webkit-transition: opacity .35s, -webkit-transform .35s;
			transition: opacity .35s, -webkit-transform .35s;
		}
		.newsitem .imgs::before {
			border-top: 1px solid #fff;
			border-bottom: 1px solid #fff;
			transform: scale(0, 1);
			-webkit-transform: scale(0, 1);
		}
		.newsitem .imgs::after {
			border-left: 1px solid #fff;
			border-right: 1px solid #fff;
			transform: scale(1, 0);
			-webkit-transform: scale(1, 0);
		}
		.newsitem .imgs:hover::before,
		.newsitem .imgs:hover::after {
			opacity: 1;
			transform: scale(1);
			-webkit-transform: scale(1);
		}
		.newsitem .imgs:hover img {
			opacity: .5;
			filter: alpha(opacity=50);
		}
		.newsitem {
			.title {
				min-height: 48px;
				font-family: 'MicrosoftYaHei';
				font-size: 18px;
				color: #222222;
				margin-top: 12px;
				margin-left: 20px;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				/* autoprefixer: off*/
				-webkit-box-orient: vertical;
				/* autoprefixer: on*/
				-webkit-line-clamp: 2;
			}
			.date {
				font-family: 'MicrosoftYaHei';
				font-size: 14px;
				margin-left: 20px;
				margin-top: 10px;
				color: #8C8C8B;
			}
		}
	}
</style>